<?php

/**
* Controller:  "Remove"
*
* This controller takes the pet selected from the secure section and
* removes that pet's record from the database.  Once deleted, it can no
* longer be viewed from the front-end of the site.
*
* Functions:  index
*
* @author     Brandon A Johnson
* @copyright  LIS4368-01: "Web Development with PHP," Spring 2010
* @version    1.0
* @date       April 24, 2010
*
*/

class Remove extends Controller {
	
	/**
	* Remove() - constructor
	*
	* allows this file to act as a valid CodeIgniter controller
	*/
	function Remove()
	{
		parent::Controller();
	}

	/**
	* Remove() - constructor
	*
	* takes the pet the user selected from the secure section and removes
	* that record from the database
	*/
	function index()
	{
		// loads the "pets" database interaction model
		$this->load->model('pets_model');
		// extracts all pet records currently in the table
		$all_pets = $this->pets_model->list_pets();
		// prepares the data to be sent to the view
		$data = array();
		$data['results'] = $all_pets;

		// if no pet has been selected...
		if($_POST['pets'] == NULL)
		{
			// reload the secure section again with the current pet record list
			$this->load->view('header');
			$this->load->view('secure', $data);
		}
		// otherwise...
		else
		{
			// prep the selection to be sent to the database
			$pet_to_delete = $_POST['pets'];

			// delete the selected pet from the database
			$this->pets_model->remove_pet($pet_to_delete);
		}

		// reload all pet record minus the one just deleted
		$all_pets = $this->pets_model->list_pets();
		$data = array();
		$data['results'] = $all_pets;
		
		// load the view, allowing the user to remove another pet if they want or return
		$this->load->view('header');
		$this->load->view('remove_pet', $data);
	}
}

/* End of file remove.php */
/* Location: ./system/application/controllers/remove.php */